<!DOCTYPE html>
<html lang="en">
<head>
    <title>确认订单</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="__STATIC__/yt_css/swiper.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/yt_css/style.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/yt_css/ipad.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/yt_css/iphone.css">
    <script type="text/javascript" src="__STATIC__/yt_js/jquery-1.9.0.min.js"></script>
    <script src="__PUBLIC__/js/global.js"></script>
    <script src="__PUBLIC__/js/pc_common.js"></script>
    <script src="__PUBLIC__/js/layer/layer.js"></script>

</head>
<body class="body">
<div class="container">
    <include file="user/new_header"/>
    <form name="cart2_form" id="cart2_form" method="post">
    <div class="qrdd_content">
        <h1>xxxx,请您确认订单</h1>
        <div class="prdd_right"><img src="__STATIC__/yt_images/tu9.png" alt=""></div>
        <div class="clear"></div>

        <div class="qrshdz">
            <h2>确认收货地址</h2>
            <span>管理收获地址</span>
            <div class="clear"></div>
            <ul id="ajax_address"></ul>
            <a href=""><button onClick="add_edit_address(0);">使用新地址</button></a>
        </div>
        <div class="qrddxx">
            <h2>确认收货地址</h2>
            <div class="shoplist">
                <div class="shophead">
                    <font>商品信息</font>
                    <span>数量</span>
                    <span>小计（元）</span>
                </div>

                <foreach name="cartList" item="v2" key="k">
                    <if condition="($v2[selected] eq '1') and ($v2[store_id] eq $v[store_id])">
                        <div class="shopbody">
                            <a href="{:U('Home/Goods/goodsInfo',array('id'=>$v2[goods_id]))}"><img src="__STATIC__/yt_images/tu2.png" alt=""></a>
                            <div class="guige">
                                <h4>{$v2.goods_name}</h4>
                            </div>
                            <div class="number">
                                <button type="button" class="minus">-</button>
                                <input type="text" class="am-num-text" value="1" />
                                <button type="button" class="plus">+</button>
                            </div>
                            <b>￥{$v2.goods_fee}</b>
                            <div class="clear"></div>
                        </div>
                    </if>
                </foreach>
            </div>
        </div>
        <select onchange="ajax_order_price();" class="vam ou-no" name="shipping_code">
            <foreach name="shippingList" item="v4" key="k4">
                <option value="{$v4.code}"  >{$v4.name}</option>
            </foreach>
        </select>
        <div class="grxx">
            <ul>
                <li class="price_info"><span>商品总金额：</span><span id="goods_price">￥{$total_price.total_fee}</span></li>
                <li class="price_info"><span>运费：</span><span id="post_fee">￥0.00</span></li>
                <li class="price_info"><span>应付金额：</span><span id="all_amount">￥0.00</span></li>
            </ul>
            <button onClick="submit_order();">提交订单</button>
            <div class="clear"></div>
        </div>
        <div class="clear"></div>
    </div>
     </form>
    <include file="public/new_footer"/>
</div>

<script type="text/javascript">
    $(document).ready(function(){
        ajax_address()
    });

    /*
     * ajax 获取当前用户的收货地址列表
     */
    function ajax_address() {
        $.ajax({
            url: "{:U('Home/Cart/ajaxAddress')}",//+tab,
            success: function (data) {
                $("#ajax_address").html('');
                $("#ajax_address").append(data);
                // 有收货地址列表 再计算价钱if (data != '')
                    ajax_order_price();
            }
        });
    }

    // 切换收货地址
    function swidth_address(obj) {
        $(".address_info").removeClass('active');
        $(obj).parent().addClass('active');
        ajax_order_price(); // 计算订单价格
    }


    /**
     * 新增修改收货地址
     * id 为零 则为新增, 否则是修改
     *  使用 公共的 layer 弹窗插件  参考官方手册 http://layer.layui.com/
     */
    function add_edit_address(id) {
        if (id > 0)
            var url = "/index.php?m=Home&c=User&a=edit_address&scene=1&call_back=call_back_fun&id=" + id; // 修改地址  '{:U('Home/User/add_address',array('scene'=>'1','call_back'=>'call_back_fun','id'=>id))}' //iframe的url /index.php/Home/User/add_address
        else
            var url = "/index.php?m=Home&c=User&a=add_address&scene=1&call_back=call_back_fun";	// 新增地址
        layer.open({
            type: 2,
            title: '添加收货地址',
            shadeClose: true,
            shade: 0.8,
            area: ['880px', '580px'],
            content: url,
        });
    }
    // 添加修改收货地址回调函数
    function call_back_fun(v) {
        layer.closeAll(); // 关闭窗口
        ajax_address(); // 刷新收货地址
    }

    // 获取订单价格
    function ajax_order_price() {
        $.ajax({
            type : "POST",
            url:"{:U('Home/Cart/cart3')}",//+tab,g
            data : $('#cart2_form').serialize()+"&act=order_price",// 你的formid
            dataType: "json",
            success: function(data){
                if(data.status != 1)
                {
                    //执行有误
                    layer.alert(data.msg, {icon: 2});
                    // 登录超时g
                    if(data.status == -100)
                        location.hrgef ="{:U('Home/User/login')}";
                    return false;
                }

                $("#post_fee").text(data.result.postFee); // 物流费


                $("#all_amount").text(data.result.payables);// 应付
            }
        });
    }

    // 提交订单
    ajax_return_status = 1;
    function submit_order()
    {
        if(ajax_return_status == 0)
            return false;
        ajax_return_status = 0;
        $.ajax({
            type : "POST",
            url:"{:U('Home/Cart/cart3')}",//+tab,
            data : $('#cart2_form').serialize()+"&act=submit_order",// 你的formid
            dataType: "json",
            success: function(data){

                if(data.status != '1')
                {
                    // alert(data.msg); //执行有误
                    layer.alert(data.msg, {icon: 2});
                    // 登录超时
                    if(data.status == -100)
                        location.href ="{:U('Home/User/login')}";

                    ajax_return_status = 1; // 上一次ajax 已经返回, 可以进行下一次 ajax请求

                    return false;
                }
                layer.msg('订单提交成功，正在跳转!', {
                    icon: 1,   // 成功图标
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function(){ // 关闭后执行的函数
                    location.href = "/index.php?m=Home&c=Cart&a=cart4&order_id="+data.result; // 跳转到结算页
                });
            }
        });
    }


</script>

</body>

</html>